package com.manage.project.biz.controller;

import java.util.List;

import com.manage.project.biz.domain.BizJidiansheshiguzhangxuncha;
import com.manage.project.biz.service.IBizJidiansheshiguzhangxunchaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.project.biz.domain.BizJidiansheshiyingjijianxiu;
import com.manage.project.biz.service.IBizJidiansheshiyingjijianxiuService;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.web.page.TableDataInfo;

/**
 Controller
 *
 * @author liutao
 *
 */
@RestController
@RequestMapping("/biz/jidiansheshiyingjijianxiu")
public class BizJidiansheshiyingjijianxiuController extends BaseController
{
    @Autowired
    private IBizJidiansheshiyingjijianxiuService bizJidiansheshiyingjijianxiuService;
    @Autowired
    private IBizJidiansheshiguzhangxunchaService bizJidiansheshiguzhangxunchaService;

    /**
     * 查询机电设施应急检修列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiyingjijianxiu:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizJidiansheshiyingjijianxiu bizJidiansheshiyingjijianxiu)
    {
        startPage();
        List<BizJidiansheshiyingjijianxiu> list = bizJidiansheshiyingjijianxiuService.selectBizJidiansheshiyingjijianxiuList(bizJidiansheshiyingjijianxiu);
        return getDataTable(list);
    }

    /**
     * 导出机电设施应急检修列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiyingjijianxiu:export')")
    @Log(title = "机电设施应急检修", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizJidiansheshiyingjijianxiu bizJidiansheshiyingjijianxiu)
    {
        List<BizJidiansheshiyingjijianxiu> list = bizJidiansheshiyingjijianxiuService.selectBizJidiansheshiyingjijianxiuList(bizJidiansheshiyingjijianxiu);
        ExcelUtil<BizJidiansheshiyingjijianxiu> util = new ExcelUtil<BizJidiansheshiyingjijianxiu>(BizJidiansheshiyingjijianxiu.class);
        return util.exportExcel(list, "机电设施应急检修数据");
    }

    /**
     * 获取机电设施应急检修详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiyingjijianxiu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizJidiansheshiyingjijianxiuService.selectBizJidiansheshiyingjijianxiuById(id));
    }

    /**
     * 新增机电设施应急检修
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiyingjijianxiu:add')")
    @Log(title = "机电设施应急检修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizJidiansheshiyingjijianxiu bizJidiansheshiyingjijianxiu)
    {
        String shebeiID = bizJidiansheshiyingjijianxiu.getField2();
        BizJidiansheshiyingjijianxiu bizJidiansheshiyingjijianxiu1 = bizJidiansheshiyingjijianxiuService.selectBizJidiansheshiyingjijianxiuByshebeiId(shebeiID);
        if (bizJidiansheshiyingjijianxiu1 != null){
            return AjaxResult.error("应急检修项目中已有该设备");
        }
        BizJidiansheshiguzhangxuncha bizJidiansheshiguzhangxuncha = bizJidiansheshiguzhangxunchaService.selectBizJidiansheshiguzhangxunchaByshebeiId(shebeiID);
        if (bizJidiansheshiguzhangxuncha != null){
            String guzhangyuanyin = bizJidiansheshiguzhangxuncha.getField9();
            if (guzhangyuanyin.contains("重大事故")||guzhangyuanyin.contains("自然灾害")){
                return toAjax(bizJidiansheshiyingjijianxiuService.insertBizJidiansheshiyingjijianxiu(bizJidiansheshiyingjijianxiu));
            }
            return AjaxResult.error("该设备不属于应急检修范围");
        }
        return AjaxResult.error("该设备未发生故障");
    }

    /**
     * 修改机电设施应急检修
     */
    @Log(title = "机电设施应急检修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizJidiansheshiyingjijianxiu bizJidiansheshiyingjijianxiu)
    {
        return toAjax(bizJidiansheshiyingjijianxiuService.updateBizJidiansheshiyingjijianxiu(bizJidiansheshiyingjijianxiu));
    }

    /**
     * 删除机电设施应急检修
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiyingjijianxiu:remove')")
    @Log(title = "机电设施应急检修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizJidiansheshiyingjijianxiuService.deleteBizJidiansheshiyingjijianxiuByIds(ids));
    }
}
